package com.ntd.study.base.java8.lombda.entity;

import java.util.ArrayList;
import java.util.List;
import java.util.function.*;

public class School {
    private final Consumer<String> consumer;
    private final Predicate intoCondition;
    private final Function<Person, Student> perToStu;
    public final UnaryOperator<Student> unaryOperator;
    public Supplier<String> supplier;
    public List<Student> studentList = new ArrayList<>();

    public School(Predicate<Integer> intoCondition, Consumer<String> consumer, Function<Person, Student> perToStu, UnaryOperator<Student> unaryOperator) {
        this.intoCondition = intoCondition;
        this.consumer = consumer;
        this.perToStu = perToStu;
        supplier = () -> {
            return "目前招生人数" + studentList.size();
        }; // 生产消息
        this.unaryOperator = unaryOperator;
    }

    public boolean into(Person student) {
        if (!intoCondition.test(student.age)) {
            return false;
        }
        studentList.add(perToStu.apply(student));
        return true;
    }

    public void pubMessage(String mes) {
        consumer.accept(mes);
    }
}
